package pers.zw.study.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter(filterName = "FilterDemo1", urlPatterns = "/*")
public class FilterDemo1 implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");

        System.out.println("FilterDemo1执行前");
        chain.doFilter(req, resp);
        System.out.println("FilterDemo1执行后");
    }

    public void init(FilterConfig config) throws ServletException {
        System.out.println("------过滤器初始化------");

    }

}
